package com.dtborad.myblog.controller;

import com.dtborad.myblog.common.MusicCrawlerUtil;
import com.dtborad.myblog.common.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/musicCrawler")
@Slf4j
@Api(tags = "在线音乐")
public class MusicCrawlerController {

    @Autowired
    private MusicCrawlerUtil musicCrawlerUtil;
    @GetMapping("/songList")
    public Result<List<Map>> getSongList(@RequestParam String name) {
        List<Map> musicList = musicCrawlerUtil.getMusicList(name);
        if(musicList.isEmpty()){
            return Result.ofFail("404", "暂无歌曲信息");
        }else {
            return Result.ofSuccess(musicList);
        }
    }
}
